//@author A0087652W
package net.mysoc.w111j.model;

import java.io.Serializable;
import java.util.Date;

/**
 * A representation of an expense.
 */
public class Expense implements Serializable {

    private int id;
    private String name;
    private String details;
    private Money price;
    private Category category;
    private PaymentType paymentType;
    private Date date;

    /**
     * Nullary constructor. This is used only by the XStream library. Do not use under normal circumstances.
     */
    public Expense() {
    }

    /**
     * Constructs an {@code Expense} object with the given details.
     *
     * @param id          an ID for the expense.
     * @param name        a name for the expense.
     * @param details     additional details for the expense.
     * @param price       the price amount for the expense.
     * @param category    the category this expense falls under.
     * @param paymentType the payment type used for this expense.
     * @param date        the date of this expense.
     */
    public Expense(int id, String name, String details, Money price, Category category, PaymentType paymentType,
                   Date date) {
        this.id = id;
        this.name = name;
        this.details = details;
        this.price = price;
        this.category = category;
        this.paymentType = paymentType;
        this.date = date;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDetails() {
        return details;
    }

    public void setDetails(String details) {
        this.details = details;
    }

    public Money getPrice() {
        return price;
    }

    public void setPrice(Money price) {
        this.price = price;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public PaymentType getPaymentType() {
        return paymentType;
    }

    public void setPaymentType(PaymentType paymentType) {
        this.paymentType = paymentType;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Expense expense = (Expense) o;

        if (id != expense.id) return false;
        if (name != null ? !name.equals(expense.name) : expense.name != null) return false;
        if (details != null ? !details.equals(expense.details) : expense.details != null) return false;
        if (price != null ? !price.equals(expense.price) : expense.price != null) return false;
        if (category != null ? !category.equals(expense.category) : expense.category != null) return false;
        if (paymentType != expense.paymentType) return false;
        if (date != null ? !date.equals(expense.date) : expense.date != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (details != null ? details.hashCode() : 0);
        result = 31 * result + (price != null ? price.hashCode() : 0);
        result = 31 * result + (category != null ? category.hashCode() : 0);
        result = 31 * result + (paymentType != null ? paymentType.hashCode() : 0);
        result = 31 * result + (date != null ? date.hashCode() : 0);
        return result;
    }
}
